package com.sg.service.biz.app.impl;

import com.sg.common.util.CommonFunctionHelper;
import com.sg.common.util.RedisUtil;
import com.sg.dto.base.app.req.QueryContTagRcordDetailReq;
import com.sg.dto.biz.app.req.AddTargetTempTagRcordComReqDto;
import com.sg.dto.biz.app.res.AddTargetTempTagRcordComRespDto;
import com.sg.dto.integration.framework.AddObjectTagComReqDto;
import com.sg.dto.integration.framework.AddObjectTagComRespDto;
import com.sg.dto.integration.framework.QueryDeptDetailComBorderReqDto;
import com.sg.dto.integration.framework.QueryDeptDetailComBorderRespDto;
import com.sg.entity.OmsBasicContentTagRecord;
import com.sg.service.base.app.MOmsBasicContentTagRecordService;
import com.sg.common.exception.Assert;
import com.wicket.okrframework.integration.OrgService;
import com.wicket.okrframework.integration.TagService;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author ：
 * @version 1.0
 * @date ：
 */
@Service
public class TagServiceImpl implements com.wicket.okrapp.biz.service.TagService {
    @Resource
    private RedisUtil redisUtil;
    @Resource
    private MOmsBasicContentTagRecordService mOmsBasicContentTagRecordService;
    @Resource
    private OrgService orgService;
    @Resource
    private TagService fwBaseTagClient;

    /**
     * D3-执行新增指标模板标签记录(公共)[5112]
     * gen by moon at 7/29/2023, 11:05:37 PM
     */
    @Trace(operationName = "D3-执行新增指标模板标签记录(公共)")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @Override
    public AddTargetTempTagRcordComRespDto addTargetTempTagRcordCom(AddTargetTempTagRcordComReqDto reqDto) {


        //virtualUsage D1-3查询部门详情(公共)(边界)  21105
        QueryDeptDetailComBorderRespDto queryDeptDetailComBorderRespDto = null;
        QueryDeptDetailComBorderReqDto queryDeptDetailComBorderReqDto = new QueryDeptDetailComBorderReqDto();
        if (reqDto != null) {
            queryDeptDetailComBorderReqDto.setDeptId(reqDto.getDeptId());//SimpleFieldAssign//sourceId:419842_1_21105
        }

        /*D1-3查询部门详情(公共)(边界)[2691]   */
        Assert.isNull(queryDeptDetailComBorderReqDto.getDeptId(), "D3-执行新增指标模板标签记录(公共)-D1-3查询部门详情(公共)(边界)-部门ID不能为空", false);
        queryDeptDetailComBorderRespDto = orgService.queryDeptDetailComBorder(queryDeptDetailComBorderReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


//virtualUsage 3-13-04查询业务应用内容标签记录详情  21099
        OmsBasicContentTagRecord omsBasicContentTagRecord = null;
        if (queryDeptDetailComBorderRespDto != null) {
            QueryContTagRcordDetailReq queryContTagRcordDetailReq = new QueryContTagRcordDetailReq();
            queryContTagRcordDetailReq.setThemeContentTypeCode("OMS_FRAMEWORK_SPACE");//sourceId:1092559_1_21099
            queryContTagRcordDetailReq.setThemeContentId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID//sourceId:1092560_1_21099
            queryContTagRcordDetailReq.setBizAppContentCode("OBJECTIVE_TEMPLATE");//sourceId:419804_1_21099
            queryContTagRcordDetailReq.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID//sourceId:419806_1_21099
            if (queryDeptDetailComBorderRespDto != null) {
                queryContTagRcordDetailReq.setTagName(queryDeptDetailComBorderRespDto.getDeptShortName());//SimpleFieldAssign//sourceId:419803_1_21099
            }
            if (reqDto != null) {
                queryContTagRcordDetailReq.setObjectContentId(reqDto.getObjectContentId());//SimpleFieldAssign//sourceId:419805_1_21099
            }

            /*3-13-04查询业务应用内容标签记录详情[4717]   */
            Assert.isNull(queryContTagRcordDetailReq.getTagName(), "D3-执行新增指标模板标签记录(公共)-3-13-04查询业务应用内容标签记录详情-标签名称不能为空", false);
            Assert.isNull(queryContTagRcordDetailReq.getObjectContentId(), "D3-执行新增指标模板标签记录(公共)-3-13-04查询业务应用内容标签记录详情-标签内容ID不能为空", false);
            Assert.isNull(queryContTagRcordDetailReq.getThemeContentTypeCode(), "D3-执行新增指标模板标签记录(公共)-3-13-04查询业务应用内容标签记录详情-主题内容类型编码不能为空", false);
            Assert.isNull(queryContTagRcordDetailReq.getThemeContentId(), "D3-执行新增指标模板标签记录(公共)-3-13-04查询业务应用内容标签记录详情-主题内容ID不能为空", false);
            Assert.isNull(queryContTagRcordDetailReq.getBizAppContentCode(), "D3-执行新增指标模板标签记录(公共)-3-13-04查询业务应用内容标签记录详情-业务应用内容类型编码不能为空", false);
            Assert.isNull(queryContTagRcordDetailReq.getSpaceId(), "D3-执行新增指标模板标签记录(公共)-3-13-04查询业务应用内容标签记录详情-创建于空间ID不能为空", false);
            omsBasicContentTagRecord = mOmsBasicContentTagRecordService.queryContTagRcordDetail(queryContTagRcordDetailReq)/*vcase invoke 本地 method 方法调用;*/;


        }
        if ((omsBasicContentTagRecord == null)) {
            //if(3-13-04查询业务应用内容标签记录详情.出参 值等于空 )  21100

            AddObjectTagComRespDto addObjectTagComRespDto = null;
            if (queryDeptDetailComBorderRespDto != null) {
                AddObjectTagComReqDto addObjectTagComReqDto = new AddObjectTagComReqDto();
                addObjectTagComReqDto.setTagSource("CREATE_SELF");//sourceId:419789_1_21106
                addObjectTagComReqDto.setIsRecommend("FALSE");//sourceId:419792_1_21106
                addObjectTagComReqDto.setBizAppCode("TARGET_TEMPLATE_APP");//CUSTOM_CONVENTION//sourceId:419794_1_21106
                addObjectTagComReqDto.setBusinessSceneCode("OBJECTIVE_TEMP_MGT");//CUSTOM_CONVENTION//sourceId:419793_1_21106
                if (queryDeptDetailComBorderRespDto != null) {
                    addObjectTagComReqDto.setTagName(queryDeptDetailComBorderRespDto.getDeptShortName());//SimpleFieldAssign//sourceId:419788_1_21106
                }

                /*D1-1新增对象标签(公共)[2757]   */
                Assert.isNull(addObjectTagComReqDto.getTagName(), "D3-执行新增指标模板标签记录(公共)-D1-1新增对象标签(公共)-标签名称不能为空", false);
                Assert.isNull(addObjectTagComReqDto.getTagSource(), "D3-执行新增指标模板标签记录(公共)-D1-1新增对象标签(公共)-标签来源方式不能为空", false);
                Assert.isNull(addObjectTagComReqDto.getIsRecommend(), "D3-执行新增指标模板标签记录(公共)-D1-1新增对象标签(公共)-是否推荐不能为空", false);
                Assert.isNull(addObjectTagComReqDto.getBizAppCode(), "D3-执行新增指标模板标签记录(公共)-D1-1新增对象标签(公共)-归属业务应用标识不能为空", false);
                Assert.isNull(addObjectTagComReqDto.getBusinessSceneCode(), "D3-执行新增指标模板标签记录(公共)-D1-1新增对象标签(公共)-归属业务场景标识不能为空", false);
                addObjectTagComRespDto = fwBaseTagClient.addObjectTagCom(addObjectTagComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


            }
            String string = null;
            if (addObjectTagComRespDto != null) {
                OmsBasicContentTagRecord omsBasicContentTagRecord_2 = new OmsBasicContentTagRecord();
                omsBasicContentTagRecord_2.setBizAppContentCode("OBJECTIVE_TEMPLATE");//sourceId:419796_1_21101
                omsBasicContentTagRecord_2.setThemeContentTypeCode("OMS_FRAMEWORK_SPACE");//sourceId:1092551_1_21101
                omsBasicContentTagRecord_2.setThemeContentId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID//sourceId:1092552_1_21101
                omsBasicContentTagRecord_2.setSubjectLifeCycle("CURRENTLY_VALID");//sourceId:419798_1_21101
                omsBasicContentTagRecord_2.setReleaseInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID//sourceId:419799_1_21101
                omsBasicContentTagRecord_2.setReleaseTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME//sourceId:419800_1_21101
                if (addObjectTagComRespDto != null) {
                    omsBasicContentTagRecord_2.setTagName(addObjectTagComRespDto.getTagName());//SimpleFieldAssign//sourceId:419795_1_21101
                }
                if (reqDto != null) {
                    omsBasicContentTagRecord_2.setObjectContentId(reqDto.getObjectContentId());//SimpleFieldAssign//sourceId:419797_1_21101
                }

                /*3-13-04新增业务应用内容标签记录[2758]   */
                Assert.isNull(omsBasicContentTagRecord_2.getTagName(), "D3-执行新增指标模板标签记录(公共)-3-13-04新增业务应用内容标签记录-标签名称不能为空", false);
                Assert.isNull(omsBasicContentTagRecord_2.getObjectContentId(), "D3-执行新增指标模板标签记录(公共)-3-13-04新增业务应用内容标签记录-标签内容ID不能为空", false);
                Assert.isNull(omsBasicContentTagRecord_2.getBizAppContentCode(), "D3-执行新增指标模板标签记录(公共)-3-13-04新增业务应用内容标签记录-业务应用内容类型编码不能为空", false);
                Assert.isNull(omsBasicContentTagRecord_2.getThemeContentTypeCode(), "D3-执行新增指标模板标签记录(公共)-3-13-04新增业务应用内容标签记录-主题内容类型编码不能为空", false);
                Assert.isNull(omsBasicContentTagRecord_2.getThemeContentId(), "D3-执行新增指标模板标签记录(公共)-3-13-04新增业务应用内容标签记录-主题内容ID不能为空", false);
                Assert.isNull(omsBasicContentTagRecord_2.getSubjectLifeCycle(), "D3-执行新增指标模板标签记录(公共)-3-13-04新增业务应用内容标签记录-主体生命周期不能为空", false);
                Assert.isNull(omsBasicContentTagRecord_2.getReleaseInductionId(), "D3-执行新增指标模板标签记录(公共)-3-13-04新增业务应用内容标签记录-发布人就职记录ID不能为空", false);
                Assert.isNull(omsBasicContentTagRecord_2.getReleaseTime(), "D3-执行新增指标模板标签记录(公共)-3-13-04新增业务应用内容标签记录-发布时间不能为空", false);
                string = mOmsBasicContentTagRecordService.addContTagRcord(omsBasicContentTagRecord_2)/*vcase invoke 本地 method 方法调用;*/;


            }
        }
//processBranchName:正常结束 ,processBranchId:21104

        AddTargetTempTagRcordComRespDto retData = new AddTargetTempTagRcordComRespDto();


        return retData;
    }

    //
}
